/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * TopicListScrean.java
 *
 * Created on 24/04/2011, 02:29:43
 */

package ClientGui;

import ClientGui.Controller;
import clientData.TopicData;

/**
 *
 * @author iziko
 */
public class TopicListScrean extends javax.swing.JFrame {

    /** Creates new form TopicListScrean */
    public TopicListScrean() {
        initComponents();
        this.disableFields(false);
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jScrollPane1 = new javax.swing.JScrollPane();
        topicList = new javax.swing.JList();
        jLabel1 = new javax.swing.JLabel();
        goBackButton = new javax.swing.JButton();
        AddTopicButton = new javax.swing.JButton();
        AddLable = new javax.swing.JLabel();
        AddText = new javax.swing.JTextField();
        AddButton = new javax.swing.JButton();
        addLabel2 = new javax.swing.JLabel();
        addLabel3 = new javax.swing.JLabel();
        jScrollPane2 = new javax.swing.JScrollPane();
        addText3 = new javax.swing.JTextArea();
        addText2 = new javax.swing.JTextField();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        topicList.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                topicListMouseClicked(evt);
            }
        });
        jScrollPane1.setViewportView(topicList);

        jLabel1.setFont(new java.awt.Font("Tahoma", 0, 18));
        jLabel1.setForeground(new java.awt.Color(255, 0, 0));
        jLabel1.setText("Choose Topic");

        goBackButton.setText("choose forum");
        goBackButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                goBackButtonActionPerformed(evt);
            }
        });

        AddTopicButton.setText("Add New Topic");
        AddTopicButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                AddTopicButtonActionPerformed(evt);
            }
        });

        AddLable.setText("Topic Title");

        AddButton.setText("Add");
        AddButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                AddButtonActionPerformed(evt);
            }
        });

        addLabel2.setText("Post Title");

        addLabel3.setText("Post Content");

        addText3.setColumns(20);
        addText3.setRows(5);
        jScrollPane2.setViewportView(addText3);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(362, 362, 362)
                        .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 168, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(106, 106, 106)
                        .addComponent(goBackButton))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(318, 318, 318)
                        .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 282, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap(293, Short.MAX_VALUE))
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap(392, Short.MAX_VALUE)
                .addComponent(AddTopicButton, javax.swing.GroupLayout.PREFERRED_SIZE, 119, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(382, 382, 382))
            .addGroup(layout.createSequentialGroup()
                .addGap(375, 375, 375)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(AddLable)
                    .addComponent(addLabel3)
                    .addComponent(addLabel2)
                    .addComponent(AddButton))
                .addGap(29, 29, 29)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(AddText)
                    .addComponent(addText2)
                    .addComponent(jScrollPane2))
                .addContainerGap(320, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(31, 31, 31)
                .addComponent(goBackButton)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jLabel1)
                .addGap(44, 44, 44)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 360, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addComponent(AddTopicButton)
                .addGap(29, 29, 29)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(AddLable)
                    .addComponent(AddText, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(10, 10, 10)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(addLabel2)
                        .addGap(18, 18, 18)
                        .addComponent(addLabel3)
                        .addGap(18, 18, 18)
                        .addComponent(AddButton))
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(addText2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 71, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap(52, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void topicListMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_topicListMouseClicked
        TopicData td = (TopicData)this.getList().getSelectedValue();
    	if (td!=null){
    		this.setVisible(false);
    		Controller.showTopic(td);
    	}
    }//GEN-LAST:event_topicListMouseClicked

    private void goBackButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_goBackButtonActionPerformed
        this.setVisible(false);
        Controller.showForumList();
    }//GEN-LAST:event_goBackButtonActionPerformed

    private void AddTopicButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_AddTopicButtonActionPerformed
         this.disableFields(true);
    }//GEN-LAST:event_AddTopicButtonActionPerformed

    private void AddButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_AddButtonActionPerformed
         Controller.addTopic(this.AddText.getText(),this.addText2.getText(),this.addText3.getText());
         this.AddText.setText("");
         this.addText2.setText("");
         this.addText3.setText("");
        this.disableFields(false);
    }//GEN-LAST:event_AddButtonActionPerformed

    /**
    * @param args the command line arguments
    */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new TopicListScrean().setVisible(true);
            }
        });
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton AddButton;
    private javax.swing.JLabel AddLable;
    private javax.swing.JTextField AddText;
    private javax.swing.JButton AddTopicButton;
    private javax.swing.JLabel addLabel2;
    private javax.swing.JLabel addLabel3;
    private javax.swing.JTextField addText2;
    private javax.swing.JTextArea addText3;
    private javax.swing.JButton goBackButton;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JList topicList;
    // End of variables declaration//GEN-END:variables

    public javax.swing.JList getList() {
        return this.topicList;
    }

    private void disableFields(boolean bool) {
        this.AddText.setVisible(bool);
        this.addText2.setVisible(bool);
        this.addText3.setVisible(bool);
         this.jScrollPane2.setVisible(bool);
        this.addLabel2.setVisible(bool);
        this.addLabel3.setVisible(bool);
        this.AddLable.setVisible(bool);
        this.AddButton.setVisible(bool);
    }
}
